package com.order.service.impl;

import com.order.service.OrderService;
import com.payment.client.response.PaymentResponse;
import com.payment.client.request.PaymentRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * dongzhihua
 * 2022/10/20 18:30
 */
@Slf4j
@Service("order-service-rest-template")
public class OrderServiceRestTemplate implements OrderService {
    @Resource
    private RestTemplate restTemplate;

//    private String paymentUrl = "http://localhost:8001";
    private String paymentUrl = "http://PAYMENT";

    @Override
    public String pay(Integer orderId) {
        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.setOrderNo(orderId + "");
//        log.info("pay {}", paymentRequest);
        return restTemplate.postForObject(paymentUrl + "/payment/create", paymentRequest, String.class);
    }

    @Override
    public PaymentResponse get(Integer orderId) {
        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.setOrderNo(orderId + "");
//        log.info("pay {}", paymentRequest);
        return restTemplate.postForObject(paymentUrl + "/payment/get", paymentRequest, PaymentResponse.class);
    }
}
